/**
 * Copyright (C) 2025 ROKAE (Beijing) Technology Co., LTD.
 * All Rights Reserved.
 *
 * Information in this file is the intellectual property of Rokae Technology Co., Ltd,
 * And may contains trade secrets that must be stored and viewed confidentially.
 *
 * @file ElectricClawWidget.h
 * @brief 电爪插件主界面
 */
#ifndef ELECTRICCLAWWIDGET_H
#define ELECTRICCLAWWIDGET_H

#include <QWidget>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonDocument>
#include <QString>
#include <QTimer>
#include <QElapsedTimer>
#include <QIntValidator>
#include <QThread>
#include <QThreadPool>

#include "log/logmanager.h"
#include "interface/interfacemanager.h"
#include "JsonWorker.h"
#include "StatusPoller.h"

namespace Ui {
class ElectricClawWidget;
}

// 电爪插件界面类
class ElectricClawWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ElectricClawWidget(QWidget *parent = nullptr);
    ~ElectricClawWidget();

    void sendRequest(const QJsonObject &requestJson, std::function<void(QJsonArray)> callback);

private slots:
    /**
    * @brief 初始化按钮点击槽函数
    * 向设备发送停止命令作为初始化校验，成功后使能控制按钮和输入框
    */
    void on_pushButton_init_clicked();

    /**
    * @brief 停止按钮点击槽函数
    * 向设备发送停止命令
    */
    void on_pushButton_stop_clicked();

    /**
    * @brief 运行按钮点击槽函数
    * 根据界面参数向设备发送启动命令
    */
    void on_pushButton_run_clicked();

    /**
    * @brief 重载 Qt 的事件函数
    * 让 ElectricClawWidget 类知道 它是否当前显示在界面上
    * 界面展示时触发
    */
    void showEvent(QShowEvent* event) override;

    /**
    * @brief 重载 Qt 的事件函数
    * 让 ElectricClawWidget 类知道 它是否当前显示在界面上
    * 界面隐藏时触发
    */
    void hideEvent(QHideEvent* event) override;

private:
    Ui::ElectricClawWidget *ui;
    bool m_is_init;
    int m_device_id;                                // 当前设备ID
    StatusPoller* m_poller;                         // 轮询设备状态的后台线程对象
    QThread* m_polling_thread;                      // 用于轮询设备状态子线程
};

#endif // ELECTRICCLAWWIDGET_H
